//
//  WJCalculateRMBTools.m
//  WJSelectedItemsDemo
//
//  Created by 王杰 on 2019/7/27.
//  Copyright © 2019 王杰. All rights reserved.
//

#import "WJCalculateRMBTools.h"

@implementation WJCalculateRMBTools



+(NSString *)notRounding:(float)price afterPoint:(int)position{
    /***************    Type definitions        ***********/
    
    // Rounding policies :
    // Original
    //    value 1.2  1.21  1.25  1.35  1.27
    // Plain    1.2  1.2   1.3   1.4   1.3
    // Down     1.2  1.2   1.2   1.3   1.2
    // Up       1.2  1.3   1.3   1.4   1.3
    // Bankers  1.2  1.2   1.2   1.4   1.3
    
    //    typedef NS_ENUM(NSUInteger, NSRoundingMode) {
    //        NSRoundPlain,   // Round up on a tie
    //        NSRoundDown,    // Always down == truncate
    //        NSRoundUp,      // Always up
    //        NSRoundBankers  // on a tie round so last digit is even
    //    };
    NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain
                                                                                                      scale:position
                                                                                           raiseOnExactness:NO
                                                                                            raiseOnOverflow:NO
                                                                                           raiseOnUnderflow:NO
                                                                                        raiseOnDivideByZero:NO];
    NSDecimalNumber *ouncesDecimal;
    NSDecimalNumber *roundedOunces;
    
    ouncesDecimal = [[NSDecimalNumber alloc] initWithFloat:price];
    roundedOunces = [ouncesDecimal decimalNumberByRoundingAccordingToBehavior:roundingBehavior];
    NSString * res = [NSString stringWithFormat:@"%@",roundedOunces];
    return [NSString stringWithFormat:@"%0.2f",[res floatValue]];
}



@end
